package com.example.administrator.testpersionn;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.example.administrator.out1.fragment.FirstFragment;
import com.example.administrator.out1.fragment.SecondFragment;
import com.jaeger.library.StatusBarUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TabarColorActivity extends AppCompatActivity {
    private ArrayList<Fragment> mFragmentList = new ArrayList<>();
    @BindView(R.id.viewPager)
    ViewPager mVpHome;
    @BindView(R.id.bnb)
    BottomNavigationBar mBottomNavigationBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tabar_color);
        ButterKnife.bind(this);
        setStatusBar();
        Toast.makeText(this, getIntent().getStringExtra("text"), Toast.LENGTH_LONG).show();
        mBottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.ic_launcher_foreground, "One"))
                .addItem(new BottomNavigationItem(R.mipmap.a, "Two"))
                .initialise();

        mBottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
            @Override
            public void onTabSelected(int position) {
                mVpHome.setCurrentItem(position);
            }

            @Override
            public void onTabUnselected(int position) {

            }

            @Override
            public void onTabReselected(int position) {

            }
        });

        mFragmentList.add(new FirstFragment());
        mFragmentList.add(new SecondFragment());


        mVpHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mBottomNavigationBar.selectTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        mVpHome.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mFragmentList.get(position);
            }

            @Override
            public int getCount() {
                return mFragmentList.size();
            }
        });
    }
    protected void setStatusBar() {
        StatusBarUtil.setTranslucentForImageViewInFragment(com.example.administrator.out1.TabarColorActivity.this, 0,null);
    }
}
